#include "tmlog.h"

TmLog::TmLog()
{
//    QDateTime dtCur = QDateTime::currentDateTime();
//    m_pLogFile = new QFile("Log/"+dtCur.toString("yyyyMMdd.log"));
    m_pLogFile = new QFile("Log/CoreFrame.log");
    if(!m_pLogFile->open(QIODevice::Append))
    {
        qDebug()<<"[Error] Log File Open Failed!";
    }
}

TmLog::~TmLog()
{
    if( m_pLogFile ){
        m_pLogFile->flush();
        m_pLogFile->close();
        m_pLogFile = NULL;
    }
}

void TmLog::log(char cType, QString strLog)
{
    QDateTime dtCur = QDateTime::currentDateTime();
    QByteArray strResult = QString("[%1] %2 %3\r\n").arg(dtCur.toString("yyyy/MM/dd-hh:mm:ss.zzz")).arg(cType).arg(strLog).toUtf8();
    if( m_pLogFile && m_pLogFile->isOpen() ){
        m_pLogFile->write(strResult);
        m_pLogFile->flush();
    }
}

void TmLog::log_I(QString strLog)
{
    log('I', strLog);
}

void TmLog::log_D(QString strLog)
{
    log('D', strLog);
}

void TmLog::log_W(QString strLog)
{
    log('W', strLog);
}

void TmLog::log_E(QString strLog)
{
    log('E', strLog);
}

